﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot4
{
    public class ParkingBoy
    {
        public List<ParkingLot> ParkingLotList { get; }

        private IPickStragtegy PickStrategy { get; set; }

        public ParkingBoy(IPickStragtegy strategy) 
        {
            PickStrategy = strategy;
            ParkingLotList = new List<ParkingLot> 
            {
                new ParkingLot{  Id =1},
                new ParkingLot{  Id =2}
            };
        }

        public int Park(Car car)
        {
            ArgumentNullException.ThrowIfNull(car);

            var parkingLot = PickStrategy.PickParkingLot(ParkingLotList);
            if (parkingLot == null)
            {
                throw new InvalidOperationException("All parking lots are full now!");
            }

            return parkingLot.Park(car);
        }

        public Car? TakeOut(int number)
        {
            foreach (var parkingLot in ParkingLotList)
            {
                var car = parkingLot.TakeOut(number);
                if (car != null)
                {
                    return car;
                }
            }

            return null;
        }
    }
}
